﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Win32;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using Zero.UControl.Demo.Helper.PDF;

namespace Zero.UControl.Demo.Views.Report
{
    /// <summary>
    /// ReportWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ReportWindow : Window
    {
        public ReportWindow()
        {
            InitializeComponent();
        }

        private void Export_Button_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "PDF | *.PDF";
            saveFileDialog.DefaultExt = "pdf";
            saveFileDialog.Title = "选择PDF保存路径";
            bool? flag = saveFileDialog.ShowDialog();
            if (flag.HasValue && flag.Value)
            {
                string fileName = saveFileDialog.FileName;

                var visuals = new List<Visual>();
                foreach (Visual child in gridParent.Children)
                {
                    visuals.Add(child);
                }
                var options = new PdfExportOptions
                {
                    Dpi = 300,
                    HeaderText = "内容标题部分",
                    FooterText = "第 {page} 页",
                    WatermarkText = "机密 Confidential",
                    Font = new XFont("Microsoft YaHei", 12, XFontStyleEx.Regular)
                };

                MultiPagePdfExporter.ExportVisualsToPdf(visuals, fileName, options);
            }
        }
    }
}
